<template>
	<view>
		<view :class="['TUI-fileMessage',isMine ? 'my-text' : 'to-text']" >
			<view  class="fileMessage" @click="enter(0)" v-if="JSON.parse(message.payload.data).businessID=='recipe_view'">
				<view class="title text-bold text-l">合同签署</view>
				<view class="content text-sm">买卖双方可以签署在线合同了，若没有在法大大实名认证过，则需实名，您可点击下方按开始操作(签署我合同中心签署)买家您好，您选择的包赔证明和交易合同享有相同的权益，可点击下方按钮获取或合同中心查看</view>
				<view class="flex align-center justify-between sign" style="font-size: 27rpx;">
					<view>{{userIinfo.user_id==1?'查看合同':'合同签署'}}</view>
					<u-icon name="arrow-right" color="#999999" size="10"></u-icon>
				</view>
			</view>
			<view  class="fileMessage" @click="enter(1)" v-else>
				<view class="title text-bold text-l">客服提醒</view>
				<view class=" content text-sm">买卖双方签署电子合同之前需进入法大大进行授权</view>
				<view class="flex align-center justify-between sign" style="font-size: 27rpx;">
					<view>进入法大大授权</view>
					<u-icon name="arrow-right" color="#999999" size="10"></u-icon>
				</view>
			</view>
			<!-- <view class="fileMessage">
				<view class="fileMessage-box">
					<image class="file-icon" src="/static/static/images/file.png"></image>
					<label @tap="download" class="file-title">{{ filePayload.fileName }}</label>
				</view>
			</view> -->
		</view>
		<!-- <view class="pop" v-if="Show">
			<view class="text-box"><text class="download-confirm" @tap.stop="downloadConfirm">下载</text></view>
			<view class="text-box"><text class="abandon" @tap="cancel">取消</text></view>
		</view> -->
	</view>
</template>

<script>
export default {
	data() {
		return {
			Show: false,
			filePayload: {},
			userIinfo:global.userInfo
		};
	},

	components: {},
	props: {
		message: {
			type: Object,
			default: () => {}
		},
		isMine: {
			type: Boolean,
			default: true
		},
	},
	watch: {
		message: {
			handler: function(newVal) {
				this.filePayload=newVal.payload
			},
			immediate: true,
			deep: true
		}
	},
	methods: {
		enter(e){
			let payload=JSON.parse(this.message.payload.data)
			if(e==0){
				console.log('客服')
				if(global.userInfo.is_kefu>0){//获取签署链接
				
					this.checkcontract(payload.signTaskId)
				}else{
					// let payload=JSON.parse(this.message.payload.data)
					console.log(payload)
					if(payload.user_id==global.userInfo.user_id){//买家
					     console.log('买家')
						 plus.runtime.openWeb(payload.user_qs_url)
					}else{//卖家
					    console.log('卖家')
						plus.runtime.openWeb(payload.to_user_id_url)
					}
					// console.log(this.authUrl)
					// window.location.href=this.authUrl
				}
			}else{//授权
			// console.log(global.userInfo.user_id)
				if(global.userInfo.user_id!=1){//获取签署链接
				    // uni.openUrl
					this.getuserAuth()
				    // uni.navigateTo({
				    // 	url:'/pages/without/webview?url='+encodeURIComponent(this.authUrl)
				    // })
				    // this.$urouter.navigateTo({
				    // 	Url:'/pages/without/webview',
				    // 	params:{
				    // 		url:encodeURIComponent(this.authUrl)
				    // 	}
				    // })
				}else{
					console.log('客服不可进入授权')
				}
			}
			
			// this.$api.get(global.apiUrls.createTemplate,{
			// 	user_id:global.userInfo.user_id,
			// }).then(res => {
			//   if(res.data.code==1){
			// 	  console.log(res)
			//   }
			// })
		},
		getuserAuth(){
			this.$api.get(global.apiUrls.userAuth,{
				user_id:global.userInfo.user_id,
			}).then(res => {
				console.log(res)
			  if(res.data.code==1){
				  this.authUrl=res.data.data.authUrl
				  plus.runtime.openWeb(this.authUrl)
			  }else{
				  uni.$u.toast(res.data.msg)
			  }
			})
		},
		checkcontract(signTaskId){
			this.$api.get(global.apiUrls.getPreviewUrl,{
				template_id:signTaskId,
			}).then(res => {
			  if(res.data.code==1){
				  console.log(res)
				  plus.runtime.openWeb(res.data.data.signTaskPreviewUrl)
			  }else{
				  uni.$u.toast(res.data.msg)
			  }
			})
		},
		// download() {
		// 	this.setData({
		// 		Show: true
		// 	});
		// },

		// downloadConfirm() {
		// 	uni.downloadFile({
		// 		url: this.filePayload.fileUrl,

		// 		success(res) {
		// 			const filePath = res.tempFilePath;
		// 			uni.openDocument({
		// 				filePath,

		// 				success() {
		// 					console.log('打开文档成功');
		// 				}
		// 			});
		// 		}
		// 	});
		// },

		// cancel() {
		// 	this.setData({
		// 		Show: false
		// 	});
		// }
	}
};
</script>
<style>
@import './index.css';
</style>
